package com.nexus.core.service.dto;

import com.nexus.core.entity.CreateByDTO;
import com.nexus.core.entity.UpdateByDTO;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.beans.Transient;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 数据传输对象的父类
 * 基本数据结构
 *
 * @Date 2025/7/23 14:20
 * @Author luzhengning
 **/
@Data
@EqualsAndHashCode(callSuper = false)
public abstract class BaseDTO implements Serializable {

    private static final long serialVersionUID = 1L;
    /**
     * 主键
     *
     * @Date 2025/7/23 15:04
     * @Author luzhengning
     **/
    protected String id;
    /**
     * 创建人
     *
     * @Date 2025/7/23 15:05
     * @Author luzhengning
     **/
    protected CreateByDTO createBy;
    /**
     * 创建时间
     *
     * @Date 2025/7/23 15:04
     * @Author luzhengning
     **/
    protected LocalDateTime createTime;
    /**
     * 修改人
     *
     * @Date 2025/7/23 15:06
     * @Author luzhengning
     **/
    protected UpdateByDTO updateBy;
    /**
     * 修改时间
     *
     * @Date 2025/7/23 15:06
     * @Author luzhengning
     **/
    protected LocalDateTime updateTime;

    /**
     * 删除标识
     * 逻辑删除
     *
     * @Date 2025/7/23 15:07
     * @Author luzhengning
     **/
    protected Integer deleted;

    /**
     * 乐观锁
     *
     * @Date 2025/7/23 15:07
     * @Author luzhengning
     **/
    protected Integer version;

    /**
     * 备注
     *
     * @Date 2025/7/23 15:08
     * @Author luzhengning
     **/
    protected String remark;

    public BaseDTO() {
    }

    public BaseDTO(String id) {
        this.id = id;
    }

    /**
     * 设置更新创建时间
     *
     * @Date 2025/7/23 15:11
     * @Author luzhengning
     **/
    protected void onCreateTime() {
        this.createTime = LocalDateTime.now();
    }

    /**
     * 设置更新修改时间
     *
     * @Date 2025/7/23 15:11
     * @Author luzhengning
     **/
    protected void onUpdateTime() {
        this.updateTime = LocalDateTime.now();
    }

    /**
     * 是否是新数据
     *
     * @Date 2025/7/23 15:14
     * @Author luzhengning
     **/
    @Transient
    public boolean isNew() {
        return this.id == null || this.id.trim().length() == 0;
    }
}
